package first.niuke.simple;

/**
 * @ClassName NC57
 * @description:
 * @author: 荣燊
 * @create: 2021-04-11 16:04
 **/
public class NC57 {
    /**
     * 反转之后会有一个溢出的问题，需要考虑
     * @param args
     */

    public static void main(String[] args) {
        int maxValue = Integer.MAX_VALUE; //-2147483648
        int minValue = Integer.MIN_VALUE;  //2147483647
        System.out.println(maxValue+","+minValue);

        System.out.println(reverse(1));
    }

    public static int reverse (int x) {
        // write code here
        int res = 0;

        while (x != 0) {
            int tmp = x % 10;
            if (res > 214748364 || (res == 214748364 && tmp > 7)) {
                return 0;
            }
            if (res < -214748364 || (res == -214748364 && tmp < -8)) {
                return 0;
            }
            res = res*10 + tmp;
            x /= 10;
        }
        return res;
    }
}
